/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ie.tcd.cs.railtickets.server.dao.impl;

import ie.tcd.cs.railtickets.server.dao.AgentDAO;
import ie.tcd.cs.railtickets.server.domain.Agent;
import static ie.tcd.cs.railtickets.server.dao.impl.HibernateSessionFactory.getSession;

/**
 *
 * @author Wenbo Sun
 */
public class AgentDAOImpl extends AbstractBaseDAOImpl implements AgentDAO {

    public Agent findByAddr(String ipAddr) {
        String query = "from Agent agent where agent.ipAddr = ?";
        Agent agent = (Agent) getSession().createQuery(query).setParameter(0, ipAddr).iterate().next();
        return agent;
    }

    public boolean isExist(String ipAddr) {
        String query = "from Agent agent where agent.ipAddr = ?";
        if(getSession().createQuery(query).setParameter(0, ipAddr).iterate().hasNext())
            return true;
        return false;
    }

}
